<?php

class Bootstrap extends Zend_Application_Bootstrap_Bootstrap {

    protected function _initAppAutoload() {
        $moduleLoader = new Zend_Application_Module_Autoloader(array(
                    'namespace' => '',
                    'basePath' => APPLICATION_PATH));

        // Carga los rosources de la forma para el module default
        $autoloader = new Zend_Application_Module_Autoloader(array(
                    'namespace' => 'Default_',
                    'basePath' => APPLICATION_PATH . '/modules/default',
                    'resourceTypes' => array(
                        'forms' => array('path' => '/forms',
                            'namespace' => 'Form')
                    )
                        )
        );

        // Carga los rosources de la forma para el module admin
        $autoloader = new Zend_Application_Module_Autoloader(array(
                    'namespace' => 'Admin_',
                    'basePath' => APPLICATION_PATH . '/modules/admin',
                    'resourceTypes' => array(
                        'forms' => array('path' => '/forms',
                            'namespace' => 'Form')
                    )
                        )
        );
    }

    protected function _initDoctrine() {
        $this->getApplication()->getAutoloader()
                ->pushAutoloader(array('Doctrine', 'autoload'));
        spl_autoload_register(array('Doctrine', 'modelsAutoload'));

        $doctrineConfig = $this->getOption('doctrine');
        $manager = Doctrine_Manager::getInstance();
        $manager->setAttribute(Doctrine::ATTR_AUTO_ACCESSOR_OVERRIDE, true);
        $manager->setAttribute(
                Doctrine::ATTR_MODEL_LOADING,
                $doctrineConfig['model_autoloading']
        );

        Doctrine_Core::loadModels($doctrineConfig['models_path']);

        $conn = Doctrine_Manager::connection($doctrineConfig['dsn'], 'doctrine');
        $conn->setAttribute(Doctrine::ATTR_USE_NATIVE_ENUM, true);
        return $conn;
    }

    protected function _initViewHelpers() {

        $this->bootstrap('layout');
        $layout = $this->getResource('layout');
        $view = $layout->getView();

        //$view->getHelper('BaseUrl')->setBaseUrl('http://' . $_SERVER['SERVER_NAME']);

        $view->doctype("XHTML1_STRICT");

        $view->headMeta()->appendHttpEquiv('Content-Type', 'text/html; charset=UTF-8')
                ->appendHttpEquiv('Content-Language', 'es_LA');

        $view->headTitle('NoSQL Blog');
        $view->headTitle()->setSeparator(' - ');

        $view->headMeta()->appendHttpEquiv('Content-Type', 'text/html;charset=utf-8');


        $view->headLink()->appendStylesheet('/styles/basic.css')
                ->headLink(array('rel' => 'favicon',
                    'href' => '/resources/images/favicon.ico'),
                        'PREPEND');

        // Added the Global Helper Path
        $view->addHelperPath("Nosql/View/Helper", "Nosql_View_Helper");
        // Add/path/to/some/helpers with class prefix 'My_View_Helper'
        $view->addHelperPath('application/modules/admin/views/helpers', 'Admin_Helper');
        //view helper for the user module
        $view->addHelperPath('application/modules/user/views/helpers', 'User_Helper');
        
    }

    protected function _initTranslation() {
        $language = "es";
        $translator = new Zend_Translate(
                        'array',
                        APPLICATION_PATH .'/../resources/languages',
                        $language,
                        array('scan' => Zend_Translate::LOCALE_DIRECTORY)
        );

        Zend_Registry::set('Zend_Translate', $translator);
    }

}